Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix: add_entry! for PSparseMatrices #959

Merged
merged 2 commits into from
Dec 2, 2023
Merged

Conversation

JordiManyer
Copy link
Member

@JordiManyer JordiManyer commented Dec 1, 2023

Copied from GridapDistributed issue 138.

In Gridap, we declare the function Algebra.add_entry, which is used to assemble an (i,j,v) triplet into different structures (counters, COOs and matrices). As usual, there are different specializations of this function. In particular, we have different functions for AbstractMatrix and AbstractSparseMatrix:

function add_entry!(combine::Function,A::AbstractSparseMatrix,v::Number,i,j)
  k = nz_index(A,i,j)
  nz = nonzeros(A)
  Aij = nz[k]
  nz[k] = combine(v,Aij)
  A
end

@inline function add_entry!(combine::Function,A::AbstractMatrix,v,i,j)
  aij = A[i,j]
  A[i,j] = combine(aij,v)
  A
end

As we can see, for AbstractMatrix we call combine(aij,v) whereas for AbstractSparseMatrix we call combine(v,aij). This leads to different behaviors when combine is not commutative. For instance, (a,b) -> a would create different matrices depending on the type.

@JordiManyer JordiManyer added the bug Something isn't working label Dec 1, 2023
@JordiManyer JordiManyer self-assigned this Dec 1, 2023
@codecov-commenter
Copy link

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (4a76c17) 88.14% compared to head (a639b11) 88.14%.

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #959   +/-   ##
=======================================
  Coverage   88.14%   88.14%           
=======================================
  Files         177      177           
  Lines       21064    21064           
=======================================
  Hits        18566    18566           
  Misses       2498     2498           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@amartinhuertas amartinhuertas merged commit cc54283 into master Dec 2, 2023
7 checks passed
@JordiManyer JordiManyer deleted the bugfix_add_entry branch December 2, 2023 00:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants